package com.hznu.googleAuthenticatorDemo.service.impl;

import com.hznu.googleAuthenticatorDemo.common.GoogleAuthenticator;
import com.hznu.googleAuthenticatorDemo.entity.User;
import com.hznu.googleAuthenticatorDemo.dao.UserDao;
import com.hznu.googleAuthenticatorDemo.service.UserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hznu.googleAuthenticatorDemo.service.base.PasswordHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DragonDoor
 * @since 2018-11-26
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Autowired
    PasswordHelper passwordHelper;

    @Override
    public String add(User user)
    {
        passwordHelper.encryptPassword(user); // 加密密码
        user.setSecret(GoogleAuthenticator.generateSecretKey());
        this.insert(user);
        return GoogleAuthenticator.getQRBarcode(user.getUsername(),user.getSecret());
    }

}
